package org.cornland.systemWarning.model;

import lombok.Data;

@Data
public class RespBean<T> {

    private boolean success = true;
    private Integer code = 0;
    private String msg = "操作成功";
    private Object data;

    public static RespBean build() {
        return new RespBean();
    }

    private RespBean() {
    }

    public RespBean<T> success(String msg) {
        this.msg = msg;
        this.code = 200;
        this.success = true;
        return this;
    }

    public static<T> RespBean<T> OK() {
        RespBean<T> r = new RespBean<T>();
        r.setSuccess(true);
        r.setCode(200);
        r.setMsg("操作成功");
        return r;
    }

    public static<T> RespBean<T> OK(String msg) {
        RespBean<T> r = new RespBean<T>();
        r.setSuccess(true);
        r.setCode(200);
        r.setMsg(msg);
        return r;
    }

    public static<T> RespBean<T> OK(T data) {
        RespBean<T> r = new RespBean<T>();
        r.setSuccess(true);
        r.setCode(200);
        r.setData(data);
        return r;
    }

    public static<T> RespBean<T> OK(String msg, T data) {
        RespBean<T> r = new RespBean<T>();
        r.setSuccess(true);
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static<T> RespBean<T> error(String msg, T data) {
        RespBean<T> r = new RespBean<T>();
        r.setSuccess(false);
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static RespBean<Object> error(int code, String msg) {
        RespBean<Object> r = new RespBean<Object>();
        r.setCode(code);
        r.setMsg(msg);
        r.setSuccess(false);
        return r;
    }

    public static RespBean<Object> error(String msg) {
        return error(500, msg);
    }



}
